package com.example.demo.service.aaaa.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
import com.example.demo.entity.aaaa.Demo;
import com.example.demo.mapper.aaaa.DemoMapper;
import com.example.demo.service.aaaa.MasterDemoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author gjy
 * @ClassName MasterDemoServiceImpl
 * @description
 * @date 2025/5/14 12:33
 */
@Service
@DS("master")
public class MasterDemoServiceImpl implements MasterDemoService {
    private final DemoMapper demoMapper;

    @Autowired
    public MasterDemoServiceImpl(DemoMapper demoMapper) {
        this.demoMapper = demoMapper;
    }

    @Override
    public Demo getDemoById(Long id) {
        System.out.println("当前数据源：" +
                DynamicDataSourceContextHolder.peek());
        return demoMapper.getDemoById(id);
    }
}
